﻿@using PagedList.Mvc
@model IEnumerable<CubicFWNet.Data.ViewModal.InventoryView>
@{
    ViewBag.Title = "原料库盘点";
    var name = ViewBag.Name;
}

<section class="content-header">
    <h1>
        原料库盘点
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index","Home")">首页</a></li>
        <li class="active">原料库盘点</li>
    </ol>
</section>

<section class="content">
    <div class="form-horizontal">
        <div class="box box-solid">
            <div class="box-nav clearfix">
                <div class="col-sm-12">
                    @*<button type="button" class="btn btn-primary" onclick="Select();" title="查询"><i class="fa fa-search"></i>&nbsp;&nbsp;查询</button>
                        <a class="btn btn-default" onclick="javascript: window.location.reload();" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a>*@
                    <form action="@Url.Action("TakeMaterial", "StorageTable")" method="post">
                        <div class="form-group col-sm-4">
                            <label class="col-sm-4 control-label no-padding-right" for=""> 名称 </label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="Name" name="Name" value="@ViewBag.Name" />
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label no-padding-right" for=""> 库房 </label>
                            <div class="col-sm-8">
                                <select class="form-control" id="StorageId" name="StorageId">
                                    @foreach (var item in @ViewBag.Storages)
                                    {
                                        <option value="@item.Id">@item.Name</option>
                                    }
                                </select>
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            @*<button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>*@
                            <button type="submit" class="btn btn-primary">查询</button>

                            <a class="btn btn-default" onclick="javascript: window.location.reload();" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a>
                        </div>
                    </form>

                </div>
            </div>
            <div class="box-body">
                <table class="footable table table-stripped table-bordered table-hover" id="footable" data-page-size="20" data-filter=#filter>
                    <thead>
                        <tr>
                            <th data-sort-ignore="true">
                                名称
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                规格
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                基本单位
                            </th>
                            @*<th data-hide="phone,tablet" data-sort-ignore="true">
                                总库存[平方米]
                            </th>*@
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        @if (null != Model)
                        {
                            foreach (var item in Model)
                            {
                                <tr>
                                    <td>
                                        <span onclick="ShowModal('@item.ProuctId')" name="ProName" id="ProName" class="linkLayout">@Html.DisplayFor(modelItem => item.ProuctName)</span>
                                        @*@Html.DisplayFor(modelItem => item.ProuctName)*@
                                    </td>
                                    <td>
                                        <span style="color: dodgerblue; cursor: pointer;" onclick="ShowModalFormat('@item.ProuctId')">规格列表</span>
                                    </td>
                                    <td>
                                        @Html.DisplayFor(modelItem => item.Unit)
                                    </td>
                                    @*<td>
                                        @Html.DisplayFor(modelItem => item.Area)
                                    </td>*@
                                    <td>
                                        <span style="color: dodgerblue; cursor: pointer;" onclick="UpdateTake('@item.Id','@item.ProuctName')">修改库存</span>
                                    </td>
                                </tr>
                            }
                        }
                    </tbody>
                    
                </table>
            </div>
        </div>
    </div>
</section>

<!--查询对话框-->
<div class="modal" id="queryDlg" style="display: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">查询</h4>
            </div>
            <form class="form-horizontal" action="@Url.Action("InventoryMaterial", "StorageTable")" method="post">
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 名称 </label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="Name" name="Name" value="@ViewBag.Name" />
                        </div>
                    </div>
                    @*<div class="form-group">
                            <label class="col-sm-3 control-label no-padding-right" for=""> 产品类型 </label>
                            <div class="col-sm-8">
                                <select class="form-control" id="Type" name="Type">
                                    <option value="0">全部</option>
                                    <option value="1">成品</option>
                                    <option value="2">原料</option>
                                </select>
                            </div>
                        </div>*@
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">查询</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!--修改销售员-->
<div class="modal" id="ModalTake" style="display: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">修改库存</h4>
            </div>
            <form id="frmUpdate" class="form-horizontal" action="@Url.Action("TakeMaterial", "StorageTable")" method="post" onsubmit="return toVaild()">
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 产品名称 </label>
                        <div class="col-sm-8">
                            <input type="hidden" id="Id" name="Id" />
                            <input type="text" class="form-control" id="c_Name" name="c_Name" readonly />
                        </div>
                    </div>
                    @*<div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 当前库存 </label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="c_Area" name="c_Area" readonly />
                        </div>
                    </div>*@
                    @*<div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 修改为 </label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="Area" name="Area" />
                        </div>
                    </div>*@
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 备注 </label>
                        <div class="col-sm-8">
                            <textarea rows="3" class="form-control" id="Memo" name="Memo" maxlength="500"></textarea>
                        </div>
                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                    <button class="btn btn-primary" onclick="SumbitTake()">确定</button>
                </div>
            </form>
        </div>
    </div>
</div>
@section Scripts {
    <script>
        $(document).ready(function () {
            $('#footable').footable();
        });

        function Select() {
            $('#queryDlg').modal();
        }
        function ShowModal(id) {
            var options = {
                id: null,
                title: '产品信息',
                width: "90%",
                height: "90%",
                url: "../Product/Info?PID=" + id,
                shade: 0.3,
                btn: ['返回'],
                btnclass: ['btn btn-danger'],
                callBack: null
            }
            $.modalOpen(options);
        }

        //弹窗显示规格列表
        function ShowModalFormat(id) {
            var options = {
                id: null,
                title: '原料规格',
                width: "90%",
                height: "90%",
                url: "../StorageTable/MaterialInventoryFormat?PID=" + id,
                shade: 0.3,
                btn: ['返回'],
                btnclass: ['btn btn-danger'],
                callBack: null
            }
            $.modalOpen(options);
        }
        //弹窗显示产品信息
        function ShowModal(id) {

            var options = {
                id: null,
                title: '产品信息',
                width: "90%",
                height: "90%",
                url: "../Product/Info?PID=" + id,
                shade: 0.3,
                btn: ['返回'],
                btnclass: ['btn btn-danger'],
                callBack: null
            }
            $.modalOpen(options);

        }

        //初始化弹窗
        function UpdateTake(id, name, amount) {
            $("#Id").val(id);
            $("#c_Name").val(name);
            //$("#c_Area").val(amount);
            $('#ModalTake').modal();
        }

        function toVaild() {
            var amount = $("#Area").val();

            if (amount == "" || amount == null) {
                $.modalAlert("【修改为】不能空", "warning");
                return false;
            }
        }

        //修改销售员
        function SumbitTake() {
            var id = $("#Id").val();
            //var camount = $("#c_Area").val();
            var amount = $("#Area").val();
            var memo = $("#Memo").val()
            $.ajax({
                url: "/StorageTable/UpdateTakeMaterial",
                type: "Post",
                data: {
                    id: id,
                    amount: amount,
                    //camount: camount,
                    memo: memo
                },
                dataType: "json",
                async: false,
                success: function (data) {
                    //location.reload();
                    $('#frmUpdate').sumbit();
                }
            });


        }
    </script>
}

